package gui;

import dto.CoberturaDTO;
import dto.EspecialidadDTO;
import dto.HorarioDTO;
import dto.MedicoDTO;
import dto.UserDTO;
import java.awt.Frame;
import java.sql.SQLException;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import logic.Cobertura;
import logic.Especialidad;
import logic.Horario;
import logic.Medico;
import logic.User;
import util.InputHelper;

/**
 *
 * @author lucifer
 */
public class UserPanel extends javax.swing.JPanel implements Slave {

  private Master master;

  public void SetMaster(Master master) {
    this.master = master;
  }

  public void SetModeActions() {
    ((JFrame) master).setTitle("Administración de Usuarios - Senzu");
  }

  public void Update() {
    setUpEspecialidadComboBox(especialidadjComboBox);
  }

  private ArrayList<Integer> uIDs;
  private ArrayList<Integer> eIDs;

  private boolean isCreatingUser = false;
  private boolean isEditingUser = false;
  private boolean hasNewPassword = false;
  private boolean hasNewHorarios = false;
  private boolean hasNewCoberturas = false;

  private User userSeleccionado;
  private String passwd;
  private ArrayList<HorarioDTO> horarios;
  private ArrayList<CoberturaDTO> coberturas;

  public UserPanel(Master master) {
    SetMaster(master);

    initComponents();

    setEditables(false);
    setUpEspecialidadComboBox(especialidadjComboBox);
    preBusqueda();
  }

  private void preBusqueda() {
    try {
      updateTabla(User.All());
    } catch (SQLException e) {
      System.out.printf("?u:database connection failed\n");
    }
  }

  private void setEditables(boolean b) {
    usernamejTextField.setEditable(b);
    clavejButton.setEnabled(b);
    regularjRadioButton.setEnabled(b);
    medicojRadioButton.setEnabled(b);
    nombrejTextField.setEditable(b);
    apellidojTextField.setEditable(b);
    matriculajTextField.setEditable(b);
    especialidadjComboBox.setEnabled(b);
    addjButton.setEnabled(b);
    telLineajTextField.setEditable(b);
    telCelularjTextField.setEditable(b);
    horariosjButton.setEnabled(b);
    coberturasjButton.setEnabled(b);
  }

  private void setMedicoEnabled(boolean b) {
    nombrejTextField.setEnabled(b);
    apellidojTextField.setEnabled(b);
    matriculajTextField.setEnabled(b);
    especialidadjComboBox.setEnabled(b);
    addjButton.setEnabled(b);
    telLineajTextField.setEnabled(b);
    telCelularjTextField.setEnabled(b);
    horariosjButton.setEnabled(b);
    coberturasjButton.setEnabled(b);
  }

  private void setAttributes(UserDTO u) throws SQLException {
    usernamejTextField.setText(u.getUsername());
    regularjRadioButton.setSelected(u.getGid() == 1);
    medicojRadioButton.setSelected(u.getGid() == 2);

    String nombre = "-";
    String apellido = "-";
    String matricula = "-";
    int especialidad = -1;
    String tel = "-";
    String cel = "-";

    if (u.getGid() == 2) {
      MedicoDTO m = Medico.SearchByID(u.getIdMedico());
      nombre = m.getNombre();
      apellido = m.getApellido();
      matricula = m.getMatricula();
      especialidad = eIDs.indexOf(m.getIdEspecialidad());
      tel = m.getTelLinea();
      cel = m.getCelular();
    }

    nombrejTextField.setText(nombre);
    apellidojTextField.setText(apellido);

    matriculajTextField.setText(matricula);
    especialidadjComboBox.setSelectedIndex(especialidad);

    telLineajTextField.setText(tel);
    telCelularjTextField.setText(cel);
  }

  private void cleanAll() {
    usernamejTextField.setText("");
    regularjRadioButton.setSelected(false);
    medicojRadioButton.setSelected(false);

    nombrejTextField.setText("");
    apellidojTextField.setText("");

    matriculajTextField.setText("");
    especialidadjComboBox.setSelectedIndex(-1);

    telLineajTextField.setText("");
    telCelularjTextField.setText("");
  }

  private UserDTO userInputForUserWithoutPassword(boolean isMedico) throws SQLException {
    int id = -1;
    int idMedico = -1;
    // En el caso de estar editando un user.
    if (userSeleccionado != null) {
      id = userSeleccionado.getId();
      idMedico = userSeleccionado.getIdMedico();
    }

    String username = usernamejTextField.getText();
    boolean repetido = false;
    if (isCreatingUser) {
      ArrayList<UserDTO> users = User.SearchByFullUsername(username);
      repetido =  !users.isEmpty();
    }
    if (username.equals("root") || InputHelper.isNonAlphabetic(username) || repetido) {
      JOptionPane.showMessageDialog(this, "Username inválido ó username existente. Ingrese correctamente el nombre de usuario, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }

    if (isCreatingUser && !hasNewPassword) {
      JOptionPane.showMessageDialog(this, "Usuario sin password. Ingrese el password del usuario con el botón `Clave', por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }

    if (!isMedico) {
      return new UserDTO(id, 1, -1, username, null);
    }

    String nombre = nombrejTextField.getText();
    if (InputHelper.isNonAlphabetic(nombre)) {
      JOptionPane.showMessageDialog(this, "Nombre inválido. Ingrese correctamente el nombre del médico, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }
    String apellido = apellidojTextField.getText();
    if (InputHelper.isNonAlphabetic(apellido)) {
      JOptionPane.showMessageDialog(this, "Apellido inválido. Ingrese correctamente el apellido del médico, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }
    String matricula = matriculajTextField.getText();
    if (InputHelper.isNonAlphanumeric(matricula)) {
      JOptionPane.showMessageDialog(this, "Matrícula inválida. Ingrese correctamente la matrícula del médico, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }
    int idEspecialidad = 0;
    try {
      idEspecialidad = eIDs.get(especialidadjComboBox.getSelectedIndex());
    } catch (ArrayIndexOutOfBoundsException e) {
      JOptionPane.showMessageDialog(this, "Especialidad médica inválida. Seleccione una especialidad médica, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }
    String telLinea = telLineajTextField.getText();
    if (InputHelper.isNonValidPhone(telLinea)) {
      JOptionPane.showMessageDialog(this, "Número de teléfono de línea inválido. Ingrese correctamente el número de télefono de línea, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }
    String celular = telCelularjTextField.getText();
    if (InputHelper.isNonValidPhone(celular)) {
      JOptionPane.showMessageDialog(this, "Número de celular inválido. Ingrese correctamente el número de celular, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }

    if (isCreatingUser && medicojRadioButton.isSelected() && !hasNewHorarios) {
      JOptionPane.showMessageDialog(this, "Médico sin horarios definidos. Ingrese los horarios del médico con el botón `Especificar Horarios', por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }

    if (isCreatingUser && medicojRadioButton.isSelected() && !hasNewCoberturas) {
      JOptionPane.showMessageDialog(this, "Médico sin coberturas definidas. Ingrese las coberturas del médico con el botón `Especificar Coberturas', por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return null;
    }

    int dni = 12345678;
    Medico medico = new Medico(idMedico, nombre, apellido, dni, matricula, idEspecialidad, telLinea, celular);
    if (userSeleccionado == null) {
      medico.Save();
    } else {
      medico.Update();
    }

    return new UserDTO(id, 2, medico.getId(), username, null);
  }

  private void createNewUser() {
    userSeleccionado = null;
    UserDTO input = null;
    try {
      input = userInputForUserWithoutPassword(medicojRadioButton.isSelected());
    } catch (SQLException ex) {
      Logger.getLogger(UserPanel.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (input == null) {
      return;
    }

    try {

      User user = new User(input);
      user.Save();
      user.ChangePasswd(passwd);

      if (user.getGid() == 2) {
        for (HorarioDTO h : horarios) {
          Horario horario = new Horario(-1, user.getIdMedico(), h.getDia(), h.getHoraDesde(), h.getHoraHasta());
          horario.Save();
        }
        for (CoberturaDTO c : coberturas) {
          Cobertura cobertura = new Cobertura(-1, user.getIdMedico(), c.getIdObraSocial(), c.getIdPlanObraSocial());
          cobertura.Save();
        }
      }

      userSeleccionado = user;

      isCreatingUser = false;
      hasNewPassword = false;
      hasNewHorarios = false;
      hasNewCoberturas = false;
      nuevojButton.setEnabled(true);
      modificarjButton.setEnabled(true);
      buscarjTable.setEnabled(true);
      buscarjTextField.setEnabled(true);
      setEditables(false);

      ArrayList<UserDTO> dtos = new ArrayList<>();
      dtos.add(User.SearchByID(userSeleccionado.getId()));
      JOptionPane.showMessageDialog(
        this,
        String.format("Se registró exitosamente al usuario %s.", userSeleccionado.getUsername()),
        "Éxito: Nuevo usuario creado",
        JOptionPane.INFORMATION_MESSAGE
      );
      updateTabla(dtos);
      buscarjTable.setRowSelectionInterval(0, 0);
      buscarjTextField.setText(userSeleccionado.getUsername());
    } catch (SQLException e) {
      Logger.getLogger(UserPanel.class.getName()).log(Level.SEVERE, null, e);
    }
  }

  private void selectUserFromTable() {
    try {
      int id = uIDs.get(buscarjTable.getSelectedRow());
      userSeleccionado = new User(User.SearchByID(id));
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, "No seleccionó ningún usuario. Seleccione un usuario, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
    }
  }

  private void editPaciente() throws SQLException {
    selectUserFromTable();

    UserDTO input = userInputForUserWithoutPassword(medicojRadioButton.isSelected());

    if (input == null) {
      return;
    }

    userSeleccionado = null;
    try {
      userSeleccionado = new User(input);
      userSeleccionado.Update();
      if (hasNewPassword) {
        userSeleccionado.ChangePasswd(passwd);
      }

      if (hasNewHorarios && userSeleccionado.getGid() == 2) {
        Horario.DeleteByMedicoID(userSeleccionado.getIdMedico());
        for (HorarioDTO h : horarios) {
          Horario horario = new Horario(-1, userSeleccionado.getIdMedico(), h.getDia(), h.getHoraDesde(), h.getHoraHasta());
          horario.Save();
        }
      }
      if (hasNewCoberturas && userSeleccionado.getGid() == 2) {
        Cobertura.DeleteByMedicoID(userSeleccionado.getIdMedico());
        for (CoberturaDTO c : coberturas) {
          Cobertura cobertura = new Cobertura(-1, userSeleccionado.getIdMedico(), c.getIdObraSocial(), c.getIdPlanObraSocial());
          cobertura.Save();
        }
      }
      isEditingUser = false;
      hasNewPassword = false;
      hasNewHorarios = false;
      hasNewCoberturas = false;
      nuevojButton.setEnabled(true);
      modificarjButton.setEnabled(true);
      buscarjTable.setEnabled(true);
      buscarjTextField.setEnabled(true);
      setEditables(false);

      ArrayList<UserDTO> dtos = new ArrayList<>();
      dtos.add(User.SearchByID(userSeleccionado.getId()));
      JOptionPane.showMessageDialog(
        this,
        String.format("Se actualizaron correctamente los datos del usuario %s.", userSeleccionado.getUsername()),
        "Éxito: Datos del usuario actualizados",
        JOptionPane.INFORMATION_MESSAGE
      );

      updateTabla(dtos);
      buscarjTable.setRowSelectionInterval(0, 0);
      buscarjTextField.setText(userSeleccionado.getUsername());
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, "Datos faltantes ó incorrectos. Ingrese los datos del usuario, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
    }
  }

  private void setUpEspecialidadComboBox(JComboBox c) {
    ArrayList<EspecialidadDTO> dtos = null;
    try {
      dtos = Especialidad.All();
    } catch (Exception e) {
      dtos = new ArrayList<>();
    }
    eIDs = new ArrayList<>();
    String[] especialidades = new String[dtos.size()];

    for (int i = 0; i < especialidades.length; i++) {
      eIDs.add(dtos.get(i).getId());
      especialidades[i] = dtos.get(i).getNombre();
    }
    c.setModel(new DefaultComboBoxModel(especialidades));
    c.setSelectedIndex(-1);
  }

  private void updateTabla(ArrayList<UserDTO> u) {
    DefaultTableModel m = new DefaultTableModel();
    m.addColumn("Username");
    m.addColumn("Médico Asociado");

    String medico;
    uIDs = new ArrayList<>();
    for (int i = 0; i < u.size(); i++) {
      uIDs.add(u.get(i).getId());
      if (u.get(i).getGid() == 2) {
        try {
          MedicoDTO dto = Medico.SearchByID(u.get(i).getIdMedico());
          medico = String.format("%s %s", dto.getNombre(), dto.getApellido());
        } catch (Exception e) {
          medico = "Nombre y apellido no disponibles";
        }
      } else {
        medico = "-";
      }
      m.addRow(
        new Object[] {
          u.get(i).getUsername(),
          medico
        }
      );
    }
    buscarjTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    buscarjTable.setModel(m);

    for (int i = 0; i < buscarjTable.getRowCount(); i++) {
      for (int j = 0; j < buscarjTable.getColumnCount(); j++) {
        buscarjTable.scrollRectToVisible(buscarjTable.getCellRect(i, j, true));
      }
    }
  }

  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    regularjRadioButton = new javax.swing.JRadioButton();
    telLineajTextField = new javax.swing.JTextField();
    nombrejTextField = new javax.swing.JTextField();
    telCelularjTextField = new javax.swing.JTextField();
    apellidojLabel = new javax.swing.JLabel();
    telLineajLabel = new javax.swing.JLabel();
    usersjScrollPane = new javax.swing.JScrollPane();
    buscarjTable = new JTable() {
      public boolean isCellEditable(int i, int j) {
        return false;
      }
    };
    usernamejTextField = new javax.swing.JTextField();
    telCelularjLabel = new javax.swing.JLabel();
    usernamejLabel = new javax.swing.JLabel();
    medicojRadioButton = new javax.swing.JRadioButton();
    nombrejLabel = new javax.swing.JLabel();
    apellidojTextField = new javax.swing.JTextField();
    matriculajTextField = new javax.swing.JTextField();
    matriculajLabel = new javax.swing.JLabel();
    nuevojButton = new javax.swing.JButton();
    modificarjButton = new javax.swing.JButton();
    especialidadjComboBox = new javax.swing.JComboBox();
    especialidadjLabel = new javax.swing.JLabel();
    clavejButton = new javax.swing.JButton();
    horariosjButton = new javax.swing.JButton();
    coberturasjButton = new javax.swing.JButton();
    buscarjTextField = new javax.swing.JTextField();
    buscarjLabel = new javax.swing.JLabel();
    aceptarjButton = new javax.swing.JButton();
    cancelarjButton = new javax.swing.JButton();
    addjButton = new javax.swing.JButton();

    regularjRadioButton.setText("Regular");
    regularjRadioButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        regularjRadioButtonActionPerformed(evt);
      }
    });

    telLineajTextField.setMaximumSize(new java.awt.Dimension(286, 27));
    telLineajTextField.setMinimumSize(new java.awt.Dimension(286, 27));
    telLineajTextField.setPreferredSize(new java.awt.Dimension(286, 27));
    telLineajTextField.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        telLineajTextFieldFocusGained(evt);
      }
    });

    nombrejTextField.setMaximumSize(new java.awt.Dimension(286, 27));
    nombrejTextField.setMinimumSize(new java.awt.Dimension(286, 27));
    nombrejTextField.setPreferredSize(new java.awt.Dimension(286, 27));
    nombrejTextField.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        nombrejTextFieldFocusGained(evt);
      }
    });

    telCelularjTextField.setMaximumSize(new java.awt.Dimension(286, 27));
    telCelularjTextField.setMinimumSize(new java.awt.Dimension(286, 27));
    telCelularjTextField.setPreferredSize(new java.awt.Dimension(286, 27));
    telCelularjTextField.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        telCelularjTextFieldFocusGained(evt);
      }
    });

    apellidojLabel.setText("Apellido");

    telLineajLabel.setText("Tel. de línea");

    buscarjTable.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {

      },
      new String [] {
        "Username", "Médico Asociado"
      }
    ) {
      Class[] types = new Class [] {
        java.lang.String.class, java.lang.String.class
      };
      boolean[] canEdit = new boolean [] {
        false, false
      };

      public Class getColumnClass(int columnIndex) {
        return types [columnIndex];
      }

      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
      }
    });
    buscarjTable.getTableHeader().setReorderingAllowed(false);
    buscarjTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(java.awt.event.MouseEvent evt) {
        buscarjTableMouseClicked(evt);
      }
    });
    buscarjTable.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyReleased(java.awt.event.KeyEvent evt) {
        buscarjTableKeyReleased(evt);
      }
    });
    usersjScrollPane.setViewportView(buscarjTable);

    usernamejTextField.setMaximumSize(new java.awt.Dimension(188, 27));
    usernamejTextField.setMinimumSize(new java.awt.Dimension(188, 27));
    usernamejTextField.setPreferredSize(new java.awt.Dimension(188, 27));
    usernamejTextField.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        usernamejTextFieldFocusGained(evt);
      }
    });

    telCelularjLabel.setText("Tel. celular");

    usernamejLabel.setText("Username");

    medicojRadioButton.setText("Médico");
    medicojRadioButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        medicojRadioButtonActionPerformed(evt);
      }
    });

    nombrejLabel.setText("Nombre");

    apellidojTextField.setMaximumSize(new java.awt.Dimension(286, 27));
    apellidojTextField.setMinimumSize(new java.awt.Dimension(286, 27));
    apellidojTextField.setPreferredSize(new java.awt.Dimension(286, 27));
    apellidojTextField.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        apellidojTextFieldFocusGained(evt);
      }
    });

    matriculajTextField.setMaximumSize(new java.awt.Dimension(286, 27));
    matriculajTextField.setMinimumSize(new java.awt.Dimension(286, 27));
    matriculajTextField.setPreferredSize(new java.awt.Dimension(286, 27));
    matriculajTextField.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        matriculajTextFieldFocusGained(evt);
      }
    });

    matriculajLabel.setText("Matrícula");

    nuevojButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/add.png"))); // NOI18N
    nuevojButton.setText("Nuevo");
    nuevojButton.setMaximumSize(new java.awt.Dimension(120, 27));
    nuevojButton.setMinimumSize(new java.awt.Dimension(120, 27));
    nuevojButton.setPreferredSize(new java.awt.Dimension(120, 27));
    nuevojButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        nuevojButtonActionPerformed(evt);
      }
    });

    modificarjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/modificar.png"))); // NOI18N
    modificarjButton.setText("Modificar");
    modificarjButton.setMaximumSize(new java.awt.Dimension(120, 27));
    modificarjButton.setMinimumSize(new java.awt.Dimension(120, 27));
    modificarjButton.setPreferredSize(new java.awt.Dimension(120, 27));
    modificarjButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        modificarjButtonActionPerformed(evt);
      }
    });

    especialidadjComboBox.setMaximumSize(new java.awt.Dimension(230, 25));
    especialidadjComboBox.setMinimumSize(new java.awt.Dimension(230, 25));
    especialidadjComboBox.setPreferredSize(new java.awt.Dimension(230, 25));

    especialidadjLabel.setText("Especialidad");

    clavejButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/password.png"))); // NOI18N
    clavejButton.setText("Clave");
    clavejButton.setMaximumSize(new java.awt.Dimension(92, 27));
    clavejButton.setMinimumSize(new java.awt.Dimension(92, 27));
    clavejButton.setPreferredSize(new java.awt.Dimension(92, 27));
    clavejButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        clavejButtonActionPerformed(evt);
      }
    });

    horariosjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/horarios.png"))); // NOI18N
    horariosjButton.setText("Especificar Horarios");
    horariosjButton.setMaximumSize(new java.awt.Dimension(286, 27));
    horariosjButton.setMinimumSize(new java.awt.Dimension(286, 27));
    horariosjButton.setPreferredSize(new java.awt.Dimension(286, 27));
    horariosjButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        horariosjButtonActionPerformed(evt);
      }
    });

    coberturasjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/coberturas.png"))); // NOI18N
    coberturasjButton.setText("Especificar Coberturas");
    coberturasjButton.setMaximumSize(new java.awt.Dimension(286, 27));
    coberturasjButton.setMinimumSize(new java.awt.Dimension(286, 27));
    coberturasjButton.setPreferredSize(new java.awt.Dimension(286, 27));
    coberturasjButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coberturasjButtonActionPerformed(evt);
      }
    });

    buscarjTextField.setMaximumSize(new java.awt.Dimension(355, 27));
    buscarjTextField.setMinimumSize(new java.awt.Dimension(355, 27));
    buscarjTextField.setPreferredSize(new java.awt.Dimension(355, 27));
    buscarjTextField.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        buscarjTextFieldFocusGained(evt);
      }
    });
    buscarjTextField.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyReleased(java.awt.event.KeyEvent evt) {
        buscarjTextFieldKeyReleased(evt);
      }
    });

    buscarjLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
    buscarjLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/search.png"))); // NOI18N
    buscarjLabel.setMaximumSize(new java.awt.Dimension(25, 27));
    buscarjLabel.setMinimumSize(new java.awt.Dimension(25, 27));
    buscarjLabel.setPreferredSize(new java.awt.Dimension(25, 27));

    aceptarjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/save.png"))); // NOI18N
    aceptarjButton.setText("Guardar");
    aceptarjButton.setMaximumSize(new java.awt.Dimension(120, 27));
    aceptarjButton.setMinimumSize(new java.awt.Dimension(120, 27));
    aceptarjButton.setPreferredSize(new java.awt.Dimension(120, 27));
    aceptarjButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        aceptarjButtonActionPerformed(evt);
      }
    });

    cancelarjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/cancelar.png"))); // NOI18N
    cancelarjButton.setText("Cancelar");
    cancelarjButton.setMaximumSize(new java.awt.Dimension(120, 27));
    cancelarjButton.setMinimumSize(new java.awt.Dimension(120, 27));
    cancelarjButton.setPreferredSize(new java.awt.Dimension(120, 27));
    cancelarjButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cancelarjButtonActionPerformed(evt);
      }
    });

    addjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/add.png"))); // NOI18N
    addjButton.setMaximumSize(new java.awt.Dimension(44, 25));
    addjButton.setMinimumSize(new java.awt.Dimension(44, 25));
    addjButton.setPreferredSize(new java.awt.Dimension(44, 25));
    addjButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        addjButtonActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
          .addGroup(layout.createSequentialGroup()
            .addComponent(buscarjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(buscarjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addComponent(usersjScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(18, 18, 18)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
              .addComponent(usernamejLabel)
              .addComponent(nombrejLabel)
              .addComponent(apellidojLabel)
              .addComponent(matriculajLabel)
              .addComponent(especialidadjLabel)
              .addComponent(telLineajLabel)
              .addComponent(telCelularjLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(especialidadjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addComponent(nombrejTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(apellidojTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(telCelularjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(matriculajTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                    .addGap(56, 56, 56)
                    .addComponent(regularjRadioButton))
                  .addComponent(usernamejTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(medicojRadioButton)
                  .addComponent(clavejButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
              .addComponent(telLineajTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(horariosjButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(coberturasjButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(nuevojButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(modificarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
          .addGroup(layout.createSequentialGroup()
            .addComponent(aceptarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(cancelarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addGap(0, 0, 0))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(buscarjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(buscarjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(nuevojButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(modificarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addGap(18, 18, 18)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(usernamejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(usernamejLabel)
              .addComponent(clavejButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(regularjRadioButton)
              .addComponent(medicojRadioButton))
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(nombrejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(nombrejLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(apellidojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(apellidojLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(matriculajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(matriculajLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(especialidadjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(especialidadjLabel))
              .addComponent(addjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(telLineajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(telLineajLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(telCelularjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(telCelularjLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(horariosjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(coberturasjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(aceptarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(cancelarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
          .addComponent(usersjScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(0, 0, 0))
    );
  }// </editor-fold>//GEN-END:initComponents

  private void buscarjTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_buscarjTextFieldFocusGained
    buscarjTextField.selectAll();
  }//GEN-LAST:event_buscarjTextFieldFocusGained

  private void buscarjTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_buscarjTextFieldKeyReleased
    String itemToSearch =  buscarjTextField.getText();
    ArrayList<UserDTO> userDTOs;
    try {
      userDTOs = User.SearchByUsername(itemToSearch);
      updateTabla(userDTOs);
      if (userDTOs.isEmpty() || buscarjTable.getSelectedRow() == -1) {
        cleanAll();
      }
      if (userDTOs.size() == 1) {
        buscarjTable.setRowSelectionInterval(0, 0);
        buscarjTableMouseClicked(null);
      }
    } catch (SQLException e) {
      JOptionPane.showMessageDialog(this, InputHelper.PanicMessage, "ERROR! Esta aplicación se cerrará", JOptionPane.ERROR_MESSAGE);
      System.exit(66);
    }
  }//GEN-LAST:event_buscarjTextFieldKeyReleased

  private void buscarjTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buscarjTableMouseClicked
    // preinit
    int sel = buscarjTable.getSelectedRow();
    if (sel == -1 || !buscarjTable.isEnabled()) {
      return;
    }

    int id = uIDs.get(sel);
    try {
      UserDTO p = User.SearchByID(id);
      setEditables(false);
      setAttributes(p);
      userSeleccionado = new User(p);
    } catch (SQLException e) {
      System.out.printf("?u:id not found\n");
    }
  }//GEN-LAST:event_buscarjTableMouseClicked

  private void buscarjTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_buscarjTableKeyReleased
    buscarjTableMouseClicked(null);
  }//GEN-LAST:event_buscarjTableKeyReleased

  private void nuevojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevojButtonActionPerformed
    isCreatingUser = true;
    nuevojButton.setEnabled(false);
    modificarjButton.setEnabled(false);
    buscarjTable.setEnabled(false);
    buscarjTextField.setEnabled(false);

    usernamejTextField.setText("Ingrese el username.");
    nombrejTextField.setText("Ingrese el nombre del médico.");
    apellidojTextField.setText("Ingrese el apellido del médico.");
    matriculajTextField.setText("Ingrese la matrícula del médico.");
    setUpEspecialidadComboBox(especialidadjComboBox);
    telLineajTextField.setText("Ingrese el teléfono de linea del médico.");
    telCelularjTextField.setText("Ingrese el teléfono celular del médico.");
    setEditables(true);

    regularjRadioButtonActionPerformed(evt);
  }//GEN-LAST:event_nuevojButtonActionPerformed

  private void regularjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_regularjRadioButtonActionPerformed
    regularjRadioButton.setSelected(true);
    medicojRadioButton.setSelected(false);
    setMedicoEnabled(false);
  }//GEN-LAST:event_regularjRadioButtonActionPerformed

  private void medicojRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_medicojRadioButtonActionPerformed
    regularjRadioButton.setSelected(false);
    medicojRadioButton.setSelected(true);
    setMedicoEnabled(true);
  }//GEN-LAST:event_medicojRadioButtonActionPerformed

  private void usernamejTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_usernamejTextFieldFocusGained
    if (!isCreatingUser) {
      return;
    }
    usernamejTextField.selectAll();
  }//GEN-LAST:event_usernamejTextFieldFocusGained

  private void nombrejTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nombrejTextFieldFocusGained
    if (!isCreatingUser) {
      return;
    }
    nombrejTextField.selectAll();
  }//GEN-LAST:event_nombrejTextFieldFocusGained

  private void apellidojTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_apellidojTextFieldFocusGained
    if (!isCreatingUser) {
      return;
    }
    apellidojTextField.selectAll();
  }//GEN-LAST:event_apellidojTextFieldFocusGained

  private void matriculajTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_matriculajTextFieldFocusGained
    if (!isCreatingUser) {
      return;
    }
    matriculajTextField.selectAll();
  }//GEN-LAST:event_matriculajTextFieldFocusGained

  private void telLineajTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_telLineajTextFieldFocusGained
    if (!isCreatingUser) {
      return;
    }
    telLineajTextField.selectAll();
  }//GEN-LAST:event_telLineajTextFieldFocusGained

  private void telCelularjTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_telCelularjTextFieldFocusGained
    if (!isCreatingUser) {
      return;
    }
    telCelularjTextField.selectAll();
  }//GEN-LAST:event_telCelularjTextFieldFocusGained

  private void modificarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificarjButtonActionPerformed
    if (userSeleccionado == null) {
      JOptionPane.showMessageDialog(this, "No seleccionó ningún usuario. Seleccione un usuario, por favor.", "Atención!", JOptionPane.WARNING_MESSAGE);
      return;
    }

    isEditingUser = true;
    nuevojButton.setEnabled(false);
    modificarjButton.setEnabled(false);
    buscarjTable.setEnabled(false);
    buscarjTextField.setEnabled(false);
    setEditables(true);

    if (userSeleccionado.getGid() == 2) {
      medicojRadioButtonActionPerformed(evt);
    } else {
      regularjRadioButtonActionPerformed(evt);
    }

    regularjRadioButton.setEnabled(false);
    medicojRadioButton.setEnabled(false);

    //setUpEspecialidadComboBox(especialidadjComboBox);
  }//GEN-LAST:event_modificarjButtonActionPerformed

  private void aceptarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarjButtonActionPerformed
    if (isCreatingUser) {
      //try {
        createNewUser();
      //} catch (SQLException e) {
      //}
    } else if (isEditingUser) {
      try {
        editPaciente();
      } catch (SQLException e) {
      }
    }
  }//GEN-LAST:event_aceptarjButtonActionPerformed

  private void clavejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clavejButtonActionPerformed
    UserPasswordDialog p = new UserPasswordDialog((Frame) master, true);
    p.setLocationRelativeTo(this);
    p.setVisible(true);

    if (p.getReturnStatus() == 1) {
      passwd = p.GetPasswd();
      hasNewPassword = true;
      /* misleading
      JOptionPane.showMessageDialog(
        this,
        String.format("El password de %s se actualizó exitosamente.", userSeleccionado != null ? userSeleccionado.getUsername() : "nuevo usuario"),
        "Éxito: Password actualizado",
        JOptionPane.INFORMATION_MESSAGE
      );
      */
    }
  }//GEN-LAST:event_clavejButtonActionPerformed

  private void horariosjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_horariosjButtonActionPerformed
    UserHorariosDialog h = new UserHorariosDialog((Frame) master, true, isCreatingUser ? -1 : userSeleccionado.getIdMedico());
    h.setLocationRelativeTo(this);
    h.setVisible(true);
    if (h.getReturnStatus() == 1) {
      horarios = h.Horarios();
      hasNewHorarios = true;
      /* misleading
      JOptionPane.showMessageDialog(
        this,
        "Se registraron los nuevos horarios exitosamente.",
        "Éxito: Horarios actualizados",
        JOptionPane.INFORMATION_MESSAGE
      );
      */
    }
  }//GEN-LAST:event_horariosjButtonActionPerformed

  private void coberturasjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_coberturasjButtonActionPerformed
    UserCoberturasDialog c = new UserCoberturasDialog((Frame) master, true, isCreatingUser ? -1 : userSeleccionado.getIdMedico());
    c.setLocationRelativeTo(this);
    c.setVisible(true);
    if (c.getReturnStatus() == 1) {
      coberturas = c.Coberturas();
      hasNewCoberturas = true;
      /*
      JOptionPane.showMessageDialog(
        this,
        "Se registraron las nuevas coberturas exitosamente.",
        "Éxito: Coberturas actualizadas",
        JOptionPane.INFORMATION_MESSAGE
      );
      */
    }
  }//GEN-LAST:event_coberturasjButtonActionPerformed

  private void addjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addjButtonActionPerformed
    int ans = JOptionPane.showConfirmDialog(
      this,
      "Se pueden crear nuevas especialidades médicas en `Ventana -> Obras Sociales'.\nDesea ir ahora a la pantalla de Obras Sociales?",
      "Creación de especialidades médicas",
      JOptionPane.YES_NO_OPTION,
      JOptionPane.QUESTION_MESSAGE
    );
    if (ans == JOptionPane.NO_OPTION) {
      return;
    }
    master.ObraSocialPanel().ShowTarifasEspecialidades();
    master.ShowSlave(master.ObraSocialPanel());
    setUpEspecialidadComboBox(especialidadjComboBox);
  }//GEN-LAST:event_addjButtonActionPerformed

  private void cancelarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarjButtonActionPerformed
    userSeleccionado = null;
    isCreatingUser = false;
    isEditingUser = false;
    hasNewPassword = false;
    hasNewHorarios = false;
    hasNewCoberturas = false;
    nuevojButton.setEnabled(true);
    modificarjButton.setEnabled(true);
    buscarjTable.setEnabled(true);
    buscarjTextField.setEnabled(true);
    setEditables(false);
    setMedicoEnabled(true);
    preBusqueda();
    cleanAll();
  }//GEN-LAST:event_cancelarjButtonActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton aceptarjButton;
  private javax.swing.JButton addjButton;
  private javax.swing.JLabel apellidojLabel;
  private javax.swing.JTextField apellidojTextField;
  private javax.swing.JLabel buscarjLabel;
  private javax.swing.JTable buscarjTable;
  private javax.swing.JTextField buscarjTextField;
  private javax.swing.JButton cancelarjButton;
  private javax.swing.JButton clavejButton;
  private javax.swing.JButton coberturasjButton;
  private javax.swing.JComboBox especialidadjComboBox;
  private javax.swing.JLabel especialidadjLabel;
  private javax.swing.JButton horariosjButton;
  private javax.swing.JLabel matriculajLabel;
  private javax.swing.JTextField matriculajTextField;
  private javax.swing.JRadioButton medicojRadioButton;
  private javax.swing.JButton modificarjButton;
  private javax.swing.JLabel nombrejLabel;
  private javax.swing.JTextField nombrejTextField;
  private javax.swing.JButton nuevojButton;
  private javax.swing.JRadioButton regularjRadioButton;
  private javax.swing.JLabel telCelularjLabel;
  private javax.swing.JTextField telCelularjTextField;
  private javax.swing.JLabel telLineajLabel;
  private javax.swing.JTextField telLineajTextField;
  private javax.swing.JLabel usernamejLabel;
  private javax.swing.JTextField usernamejTextField;
  private javax.swing.JScrollPane usersjScrollPane;
  // End of variables declaration//GEN-END:variables
}
